#include "include.h"
#include "app/appmain.h"

#include "compile/debug_memoryleaks"

using namespace gui;
using namespace app;

AppMain::AppMain()
: invoker(&root), gui(&root, &invoker)
{
	//ctor

}

AppMain::~AppMain()
{
	//dtor
	done();
}



#ifdef USE_QT

void AppMain::init(int & argc, char * argv[])
{
    QApplication* qtapp = new QApplication(argc, argv);

    gui.init();
}

void AppMain::done()
{
    gui.done();
    delete QApplication::instance();
}

int AppMain::run()
{
	return QApplication::instance()->exec();
}

#elif defined USE_WXW


void AppMain::init(int & argc, char * argv[])
{
    wxApp::SetInstance(new wxApp());
	wxInitialize(argc, argv);

    gui.init(&maincontroller);
}

void AppMain::done()
{    
    gui.done();

    wxUninitialize();
    delete wxApp::GetInstance();
    wxApp::SetInstance(NULL);

}

int AppMain::run()
{
    return wxTheApp->OnRun();
}

#else // USE_NULL

void AppMain::init(int & argc, char * argv[])
{
	std::cout<<"AppMain::init"<<std::endl;
	gui.init();
}

void AppMain::done()
{
	std::cout<<"AppMain::done"<<std::endl;
	gui.done();
}

int AppMain::run()
{
	std::cout<<"AppMain::run"<<std::endl;
	return 0;
}

#endif





